//
//  LGMineViewController.m
//  ligenyun
//
//  Created by Mac on 2018/3/16.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGMineViewController.h"
#import "LGPersonnalViewController.h"
#import "LGAccountMangeViewController.h"
#import "LGLingyuanMangeViewController.h"
#import "LGJIaPuMangeViewController.h"
#import "LGMineJiSiRecordViewController.h"
#import "LGArticleMangeViewController.h"
#import "LGAccountBidingViewController.h"
#import "LGSuggestViewController.h"
#import "LGSettingViewController.h"
@interface LGMineViewController ()
@property(nonatomic, strong) NSArray                     *dataSouce;
@end

@implementation LGMineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的";

    [self configSubViewWithUserModel:nil];
        [self configDataSouce];
    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configSubViewWithUserModel:(LGUserModel*)userModel{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 95)];
    header.backgroundColor = [UIColor whiteColor];
    
    STButton * buyButton = [[STButton alloc] initWithFrame:CGRectMake(20, 0, 70, 70)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:[UIImage imageNamed:@"1"]
                                                     image:nil];
    buyButton.centerY = header.height / 2;
    buyButton.userInteractionEnabled = NO;
    [header addSubview:buyButton];
    
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(buyButton.right + 10, buyButton.top + 5, UIScreenWidth - 44 - buyButton.right - 10, 18)
                                                     text:@"昵称:大佬"
                                                textColor:FirstTextColor
                                                     font:13
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [header addSubview:titleLable];
    
    STLabel * moneyLable = [[STLabel alloc] initWithFrame:CGRectMake(buyButton.right + 10, titleLable.bottom + 5, 200, 18)
                                                     text:@"礼根币:3000币"
                                                textColor:SecendTextColor
                                                     font:13
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [NSString lableAutoAdjustWitdhWithLabel:moneyLable];
    [header addSubview:moneyLable];
    
    STLabel * scoreLable = [[STLabel alloc] initWithFrame:CGRectMake(buyButton.right + 10, moneyLable.bottom + 5, 200, 20)
                                                     text:@"积分:3000币"
                                                textColor:SecendTextColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [NSString lableAutoAdjustWitdhWithLabel:scoreLable];
    [header addSubview:scoreLable];
    
    
    STButton * qiandaoButton = [[STButton alloc] initWithFrame:CGRectMake(20+ moneyLable.right, moneyLable.right, 70, 25)
                                                     title:@"签到"
                                                titleColor:FlatWhite
                                                 titleFont:14
                                              cornerRadius:4
                                           backgroundColor:RGB(0xBCBCBC)
                                           backgroundImage:nil
                                                     image:nil];
    qiandaoButton.centerY = moneyLable.centerY;
    qiandaoButton.userInteractionEnabled = YES;
    qiandaoButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [header addSubview:qiandaoButton];
    
    STButton * indicatorButton = [[STButton alloc] initWithFrame:CGRectMake(20+ moneyLable.right, moneyLable.right, 44, 44)
                                                         title:@""
                                                    titleColor:FlatWhite
                                                     titleFont:14
                                                  cornerRadius:4
                                               backgroundColor:nil
                                               backgroundImage:nil
                                                         image:[UIImage imageNamed:@"陵墓管理~下拉"]];
    indicatorButton.centerY = header.height / 2;
    indicatorButton.userInteractionEnabled = YES;
    indicatorButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    indicatorButton.right = UIScreenWidth - self.insetX;
    [header addSubview:indicatorButton];
    
    UITapGestureRecognizer * ges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSlectedUserView)];
    [header addGestureRecognizer:ges];
    self.tableView.tableHeaderView = header;
    
}
- (void)configDataSouce{
    
    NSArray * sectionOne = @[[[STTableEasyModel alloc] initWithTextString:@"账户管理" imageName:@"账号绑定"]];
    
    NSArray * sectionTwo = @[
                             [[STTableEasyModel alloc] initWithTextString:@"陵园管理" imageName:@"账号绑定"],
                             [[STTableEasyModel alloc] initWithTextString:@"家谱管理" imageName:@"账号绑定"],
                             [[STTableEasyModel alloc] initWithTextString:@"我的祭祀记录" imageName:@"账号绑定"],
                             [[STTableEasyModel alloc] initWithTextString:@"文章管理" imageName:@"账号绑定"],
                             [[STTableEasyModel alloc] initWithTextString:@"账号绑定" imageName:@"账号绑定"]
                             ];
    NSArray * sectionThree = @[
                             [[STTableEasyModel alloc] initWithTextString:@"意见反馈" imageName:@"账号绑定"],
                             [[STTableEasyModel alloc] initWithTextString:@"设置" imageName:@"账号绑定"],
                             ];
    self.dataSouce = @[sectionOne,sectionTwo,sectionThree];
    [self.tableView reloadData];
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.dataSouce.count ;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [self.dataSouce[section] count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 49;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 15;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];
        
    }
    STTableEasyModel * model = self.dataSouce[indexPath.section][indexPath.row];
    [cell setSt_tableEasyModel:model];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    STTableEasyModel * model = self.dataSouce[indexPath.section][indexPath.row];
    if ([model.textString isEqualToString:@"账户管理"]) {
        LGAccountMangeViewController * vc = [LGAccountMangeViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([model.textString isEqualToString:@"陵园管理"]) {
        LGLingyuanMangeViewController * vc = [LGLingyuanMangeViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([model.textString isEqualToString:@"家谱管理"]) {
        LGJIaPuMangeViewController * vc = [LGJIaPuMangeViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([model.textString isEqualToString:@"我的祭祀记录"]) {
        LGMineJiSiRecordViewController * vc = [LGMineJiSiRecordViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([model.textString isEqualToString:@"文章管理"]) {
        LGArticleMangeViewController * vc = [LGArticleMangeViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([model.textString isEqualToString:@"账号绑定"]) {
        LGAccountBidingViewController * vc = [LGAccountBidingViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([model.textString isEqualToString:@"意见反馈"]) {
        LGSuggestViewController * vc = [LGSuggestViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([model.textString isEqualToString:@"设置"]) {
        LGSettingViewController * vc = [LGSettingViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
#pragma mark --Action Method
- (void)onSlectedUserView{
    LGPersonnalViewController * vc = [LGPersonnalViewController new];
    vc.userModel = nil;
    [self.navigationController pushViewController:vc animated:YES];
}
@end
